/*
  Vertexes source code

*/

#ifndef VERTEXES_C
#define VERTEXES_C

#define GL_GLEXT_PROTOTYPES

#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glu.h>
#include <GL/glext.h>
#include <GL/glcorearb.h>


unsigned int CreateVBO(float* verts, unsigned int size) {
  unsigned int VBO;
  glGenBuffers(1, &VBO);
  glBindBuffer(GL_ARRAY_BUFFER, VBO);
  glBufferData(GL_ARRAY_BUFFER, size, verts, GL_STATIC_DRAW);
  return VBO;
};

unsigned int CreateEBO(unsigned int* inds, unsigned int size) {
  unsigned int EBO;
  glGenBuffers(1, &EBO);
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
  glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, inds, GL_STATIC_DRAW);
  return EBO;
};

unsigned int CreateVAO(float* verts, unsigned int size, unsigned int* inds, unsigned int sizei) {
  unsigned int VAO;
  glGenVertexArrays(1, &VAO);
  glBindVertexArray(VAO);

  unsigned int VBO, EBO;
  VBO = CreateVBO(verts, size);
  if(inds)
    EBO = CreateEBO(inds, sizei);

  /* Атрибут 0 соответствует координатам вершины */
  glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
  glEnableVertexAttribArray(0); /* Активируем атрибут 0 */
  glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3*sizeof(float)));
  glEnableVertexAttribArray(1); /* Активируем атрибут 1 */


  return VAO;
};

#endif
